﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>图层叠加分析</title>
    <!--导入外部样式表-->
    <link href="../../css/openlayers/style.css" rel="stylesheet" type="text/css"/>
    <!--必要的脚本引用-->
    <script include="jquery" src="./static/libs/include-lib-local.js"></script>
    <script src="./static/libs/include-openlayers-local.js"></script>
    <script type="text/javascript">
        /*==========================================底图显示===================================================*/
        var map, vectorLayer;
        //缓存结果图层的基地址
        var resultBaseUrl = "gdbp://MapGisLocal/OpenLayerVecterMap/sfcls/";
        var { protocol, ip, port } = window.webclient;

        /** 地图初始化函数*/
        function init() {
            //初始化地图容器
            map = new ol.Map({
                target: "mapCon",
                view: new ol.View({
                    center: [0, 0],
                    zoom: 2,
                    projection: "EPSG:4326"
                })
            });
            //初始化地图文档图层对象
            vectorLayer = new Zondy.Map.GdbpLayer("MapGIS IGS VectorLayer", ["gdbp://MapGisLocal/OpenLayerVecterMap/ds/世界地图经纬度/sfcls/世界政区"], {
                ip: `${ip}`,
                port: `${port}`,
                //缓存名称
                guid: (new Date()).getTime().toString()
            });
            //将地图文档图层加载到地图中
            map.addLayer(vectorLayer);
        }

        /** 执行图层叠加分析*/
        function OverlayByLayerAnalysis() {
            clearA();
            //显示进度条
            startPressBar();
            //结果图层的名称
            var resultname = resultBaseUrl + "overLayByLayerAnalysisResultLayer" + getCurentTime();
            //实例化OverlayByLayer类
            var overlayParam = new Zondy.Service.OverlayByLayer({
                //IGServer所在ip地址
                ip: `${ip}`,
                //IGServer请求端口号
                port: `${port}`,
                //设置被叠加图层URL
                srcInfo1: "gdbp://MapGisLocal/OpenLayerVecterMap/ds/世界地图经纬度/sfcls/世界河流",
                //设置叠加图层URL
                srcInfo2: "gdbp://MapGisLocal/OpenLayerVecterMap/ds/世界地图经纬度/sfcls/世界政区",
                //设置结果URL
                desInfo: resultname,
                //设置结果图层的图形参数信息
                infoOptType: 2,
                //求交
                overType: 1,
                //允许重算面积
                isReCalculate: true,
                //容差半径
                radius: 0.05
            });
            //调用基类的execute方法，执行叠加分析， onSuccess为结果回调函数
            overlayParam.execute(AnalysisSuccess, "post", false, "json", AnalysisError);
        }

        /** 分析失败回调*/
        function AnalysisError(e) {
            //停止进度条
            stopPressBar();
        }

        /** 分析成功后的回调*/
        function AnalysisSuccess(data) {
            //停止进度条
            stopPressBar();
            if (!data.succeed) {
                alert("图层叠加分析，请检查参数！");
            } else {
                if (data.results.length !== 0) {
                    var resultLayerUrl = data.results[0].Value;
                    //将结果图层添加到地图视图中显示
                    var resultLayer = new Zondy.Map.GdbpLayer("MapGIS IGS overLayAnalyResultLayer", [resultBaseUrl + resultLayerUrl], {
                        ip: `${ip}`,
                        port: `${port}`,
                        //缓存名称
                        guid: (new Date()).getTime().toString()
                    });
                    map.addLayer(resultLayer);
                }
            }
        }

        /** 清除客户端分析结果信息*/
        function clearA() {
            stopPressBar(); //停止进度条
            if (map.getLayers().array_.length > 1) {
                for (var i = map.getLayers().array_.length - 1; i > 0; i--) {
                    map.removeLayer(map.getLayers().array_[i]);
                }
            } else
                return;
        }

        /** 当前日期加时间(如:2009-06-12-120000)*/
        function getCurentTime() {
            var now = new Date();
            //获取当前年份
            var year = now.getFullYear();
            //获取当前月份
            var month = now.getMonth() + 1;
            //获取当前日期
            var day = now.getDate();
            //获取当前时刻
            var hh = now.getHours();
            //获取当前分钟
            var mm = now.getMinutes();
            //获取当前秒钟
            var ss = now.getSeconds();
            //将当前的日期拼串
            var clock = year + "-";
            if (month < 10)
                clock += "0";
            clock += month + "-";
            if (day < 10)
                clock += "0";
            clock += day + "-";
            if (hh < 10)
                clock += "0";
            clock += hh;
            if (mm < 10) clock += '0';
            clock += mm;
            if (ss < 10) clock += '0';
            clock += ss;
            return (clock);
        }

        /** 停止进度条*/
        function stopPressBar() {
            document.getElementById('preview').style.display = "none";
        }

        /** 开始进度条动画*/
        function startPressBar() {
            document.getElementById('preview').style.display = "";
        }
    </script>
</head>

<body onload="init()">
<div id="preview" style="display: none; text-align: center; padding-top: 250px;font-weight:bold">
    <img src="./static/assets/graphic-image/39-1.gif" alt=''/><br/><br/>
    <span>正在执行叠加分析，请稍候</span>
</div>
<div class="ToolLib">
    <input type="button" class="ButtonLib" value="图层叠加分析" onclick="OverlayByLayerAnalysis()"/>
    <input type="button" class="ButtonLib" value="清除结果" onclick="clearA()"/>
</div>
<div id="mapCon" style="width:100%; height: 90%;position:absolute"></div>
</body>

</html>
